package com.example.Controller;

import com.example.Pojo.PageQuery;
import com.example.Pojo.Result;
import com.example.Pojo.Student;
import com.example.Service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping()
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("查询所有学生信息");
//        System.out.println(page);
//        System.out.println(pageSize);
        PageQuery<Student> studentPage=studentService.list(page, pageSize);
        return Result.success(studentPage);
    }

    @PostMapping()
    public Result addStudent(@RequestBody Student student){
        log.info("新增学生信息");
        studentService.addStudent(student);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteStudent(@PathVariable Integer id){
        log.info("删除学生信息");
        studentService.deleteStudent(id);
        return Result.success();
    }

    @PutMapping()
    public Result updateStudent(@RequestBody Student student){
        log.info("更新学生信息");
        studentService.updateStudent(student);
        return Result.success();
    }
}
